/**
 * Created by MrLiu on 2016/3/4.
 */
(function($){

    var messager = {
        alert : function(title,message,onEscape,callback){
            onEscape = onEscape == undefined ? true : onEscape;
            bootbox.dialog({
                title : title,
                message : message,
                className : "messager",
                onEscape : onEscape,
                backdrop : true,
                buttons : {
                    ok: {
                        label: '确定',
                        callback: function() {
                            if(callback && typeof(callback)=='function'){
                                callback();
                            }
                        }
                    }
                }
            });
        },
        error : function(title,message,onEscape,callback){
            onEscape = onEscape == undefined ? true : onEscape;
            bootbox.dialog({
                title : title,
                message : message,
                className : "messager messager-error",
                onEscape : onEscape,
                backdrop : true,
                buttons : {
                    ok: {
                        label: '确定',
                        callback: function() {
                            if(callback && typeof(callback)=='function'){
                                callback();
                            }
                        }
                    }
                }
            });
        },
        confirm : function(title,message,callback){
            bootbox.dialog({
                title : title,
                message : message,
                className : "messager",
                backdrop : true,
                buttons : {
                    ok: {
                        label: "确定",
                        className : "btn-primary",
                        callback: function() {
                            if(callback && typeof(callback)=='function'){
                                callback(true);
                            }
                        }
                    },
                    cancel: {
                        label: '取消',
                        className : "btn-default",
                        callback: function() {
                            if(callback && typeof(callback)=='function'){
                                callback(false);
                            }
                        }
                    }
                }
            });
        },
        show : function(title,message,timeout,callback){
            var timeout = timeout == undefined ? 3000 : timeout;
            var d = bootbox.dialog({
                title : title,
                message : message,
                className : "messager",
                backdrop : false,
                size : "small",
                buttons : {
                    ok: {
                        label: '确定',
                        callback: function() {
                            if(callback && typeof(callback)=='function'){
                                callback();
                            }
                        }
                    }
                }
            });
            window.setTimeout(function(){
                d.modal("hide");
            },timeout);

        },
        toast : function(message,positionClass,timeout,callback){
            var timeout = timeout == undefined ? 5000 : timeout;
            var positionClass = positionClass == undefined ? "toast-top-right" : positionClass;
            toastr.options = {
                "positionClass": positionClass,
                "timeOut": timeout,
                onclick : function(){
                    if(callback && typeof(callback)=='function'){
                        callback();
                    }
                }
            }
            toastr.success(message);
        }
    }


    $.extend({
        messager : messager
    });
})(jQuery);